#include "abstractdelegate.h"

AbstractDelegate::AbstractDelegate(QObject *parent) :
  QStyledItemDelegate(parent)
{
}

QSize AbstractDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
  return QSize(option.rect.width(),60);
}

void AbstractDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
  painter->save();
  painter->setRenderHints(QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing);

  QRect r = option.rect;
  bool selected = option.state & QStyle::State_Selected;

  {
    painter->setPen(QPen(Qt::transparent));
    painter->setBrush(selected ? selectedRectBrush(r) : rectBrush(r));
    painter->drawRect(r);

    painter->setPen(selected ? selectedRectPen(r) : rectPen(r));
    painter->drawLine(r.bottomLeft(),r.bottomRight());
  }

  {
    QFont f;
    f.setPointSize(fontSize(r));
    painter->setFont(f);

    if (option.state & QStyle::State_Enabled)
    {
      painter->setPen(selected ? selectedTextPen(r) : textPen(r));
    }
    else
    {
      painter->setPen(disabledTextPen(r));
    }

    painter->drawText(r.x()+leftMargin(r),
                      r.y(),r.width()-leftMargin(r),
                      r.height(),
                      Qt::AlignVCenter | Qt::AlignLeft,
                      index.data().toString());
  }

  painter->restore();
}
